package net.dgg.dggcloud.service.jrcrm.service.orf;

import net.dgg.dggcloud.core.minidao.hibernate.dao.IGenericBaseCommonDao;
import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.jrcrm.dao.orf.PayCostRecordDao;
import net.dgg.dggcloud.service.jrcrm.dao.orf.PaymentAuditorRecordDao;
import net.dgg.dggcloud.service.jrcrm.entity.orf.PaymentAuditorRecord;
import net.dgg.dggcloud.service.entity.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 财务 审核记录
 *
 * @author 郭伟 2017/11/2
 */
@Service
public class PaymentAuditorRecordService extends BaseService {

    @Autowired
    private PaymentAuditorRecordDao paymentAuditorRecordDao;

    @Resource(name="miniDaoHiberCommonDao")
    protected IGenericBaseCommonDao repository;


    /**
     *   根据
     * @param map
     *  type 类型 1 核款 ，2 退款，3 费用申请
     *  paymentId 财务ID
     * @return
     */
    public List<Map> listPayAuditorRecordMap(Map map) {
       return paymentAuditorRecordDao.listPayAuditorRecordMap(map);
    }


    /**
     *   保存操作记录
     * @param user 操作人
     * @param id 财务ID
     * @param nodeName 财务ID
     * @param content 驳回内容
     * @param type 1 核款 ，2 退款，3 费用申请
     * @param status 0 发起 1 通过 2 驳回 3 完成 4撤销
     */
    public void saveRecord(User user, Long id, String content,Integer type,Integer status,String nodeName){

        PaymentAuditorRecord paymentAuditorRecord = new PaymentAuditorRecord();
        paymentAuditorRecord.setCreateUser(user);
        paymentAuditorRecord.setId(keyWorker.nextId());
        paymentAuditorRecord.setType(type);
        paymentAuditorRecord.setUpdaterUser(user);
        paymentAuditorRecord.setAuditUserId(user.getId());
        paymentAuditorRecord.setAuditTime(new Date());
        paymentAuditorRecord.setContent(content);
        paymentAuditorRecord.setPaymentId(id);
        paymentAuditorRecord.setNodeName(nodeName);
        paymentAuditorRecord.setStatus(status);
        paymentAuditorRecordDao.saveByHiber(paymentAuditorRecord);

    }

}
